package com.woniuxy.oldmanapi.controller;

import com.woniuxy.oldmanapi.entity.*;
import com.woniuxy.oldmanapi.service.*;
import com.woniuxy.oldmanapi.vo.HealthVo;
import com.woniuxy.oldmanapi.vo.HeightVo;
import com.woniuxy.oldmanapi.vo.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class HealthController {

    @Autowired
    HeightService heightService ;
    @Autowired
    BpService bpService ;
    @Autowired
    GluService gluService ;
    @Autowired
    PulseService pulseService ;
    @Autowired
    TempService tempService ;
    @Autowired
    WeightService weightService ;
    @Autowired
    HrService hrService ;



    @PostMapping("/health/add")
    public ResponseResult<Void> add(@RequestBody HealthVo healthVo){
        ResponseResult<Void> result = new ResponseResult<>();
        try {
            if(healthVo.getHeightNum()!=null){
                OlderHeight height = new OlderHeight();
                height.setId(healthVo.getId());
                height.setOlderId(healthVo.getOlderId());
                height.setCollectDate(healthVo.getCollectDate());
                height.setNum(healthVo.getHeightNum());
                heightService.add(height);
            }
            if(healthVo.getGluNum()!=null){
                OlderGlu glu = new OlderGlu();
                glu.setId(healthVo.getId());
                glu.setOlderId(healthVo.getOlderId());
                glu.setCollectDate(healthVo.getCollectDate());
                glu.setNum(healthVo.getGluNum());
                gluService.add(glu);
            }
            if(healthVo.getTempNum()!=null){
                OlderTemp temp = new OlderTemp();
                temp.setId(healthVo.getId());
                temp.setOlderId(healthVo.getOlderId());
                temp.setCollectDate(healthVo.getCollectDate());
                temp.setNum(healthVo.getTempNum());
                tempService.add(temp);
            }
            if(healthVo.getHighbpNum()!=null){
                OlderBp bp = new OlderBp();
                bp.setId(healthVo.getId());
                bp.setOlderId(healthVo.getOlderId());
                bp.setCollectDate(healthVo.getCollectDate());
                bp.setHighbpNum(healthVo.getHighbpNum());
                bp.setLowbpNum(healthVo.getLowbpNum());
                bpService.add(bp);
            }
            if(healthVo.getPulseNum()!=null){
                OlderPulse pulse = new OlderPulse();
                pulse.setId(healthVo.getId());
                pulse.setOlderId(healthVo.getOlderId());
                pulse.setCollectDate(healthVo.getCollectDate());
                pulse.setNum(healthVo.getPulseNum());
                pulseService.add(pulse);
            }
            if(healthVo.getHrNum()!=null){
                OlderHr hr = new OlderHr();
                hr.setId(healthVo.getId());
                hr.setOlderId(healthVo.getOlderId());
                hr.setCollectDate(healthVo.getCollectDate());
                hr.setNum(healthVo.getHrNum());
                hrService.add(hr);
            }
            if(healthVo.getWeightNum()!=null){
                OlderWeight weight = new OlderWeight();
                weight.setId(healthVo.getId());
                weight.setOlderId(healthVo.getOlderId());
                weight.setCollectDate(healthVo.getCollectDate());
                weight.setNum(healthVo.getWeightNum());
                weightService.add(weight);
            }
            result.setCode(200);
            result.setMsg("添加成功!");
        }catch (Exception e) {
            e.printStackTrace();
            result.setCode(201);
            result.setMsg("添加失败!");
        }
        return result ;
    }
}
